TemplateReporter.write   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 7
c 0
b 0
f 0
rs 10
cc 1
1
import fs from 'fs-extra';
2
import handleBars from '../handlebars';
3
import Base from  './Base';
4
5
export default class TemplateReporter extends Base {
6
    constructor(file, { path, templateOpts = {} } = {}) {
7
        super(file);
8
        this.templatePath = path;
9
        this.templateOpts = templateOpts;
10
    }
11
12
    _generate(groups, map) {
13
        return this._template({
14
            groups,
15
            actions : map,
16
            options : this.templateOpts
17
        });
18
    }
19
20
    async _init() {
21
        const templateContent = await fs.readFile(this.templatePath);
22
23
        this._template = handleBars.compile(templateContent.toString(), { preventIndent: true });
24
    }
25
26
    async write(actions) {
27
        await this._init();
28
        const { groups, map } = this._build(actions, { groupBy: [ 'context.group', 'context.title' ] });
29
        const content = this._generate(groups, map, actions);
30
31
        await fs.writeFile(this.file, content);
32
    }
33
}
34